@@ -141,6 +141,34 @@ static ssize_t max_comp_streams_store(struct device *dev,
141141 return len ;
142142}
143143
144+ static ssize_t comp_algorithm_show (struct device * dev ,
145+ struct device_attribute * attr , char * buf )
146+ {
147+ size_t sz ;
148+ struct zram * zram = dev_to_zram (dev );
149+
150+ down_read (& zram -> init_lock );
151+ sz = zcomp_available_show (zram -> compressor , buf );
152+ up_read (& zram -> init_lock );
153+
154+ return sz ;
155+ }
156+
157+ static ssize_t comp_algorithm_store (struct device * dev ,
158+ struct device_attribute * attr , const char * buf , size_t len )
159+ {
160+ struct zram * zram = dev_to_zram (dev );
161+ down_write (& zram -> init_lock );
162+ if (init_done (zram )) {
163+ up_write (& zram -> init_lock );
164+ pr_info ("Can't change algorithm for initialized device\n" );
165+ return - EBUSY ;
166+ }
167+ strlcpy (zram -> compressor , buf , sizeof (zram -> compressor ));
168+ up_write (& zram -> init_lock );
169+ return len ;
170+ }
171+
144172/* flag operations needs meta->tb_lock */
145173static int zram_test_flag (struct zram_meta * meta , u32 index ,
146174 enum zram_pageflags flag )
@@ -572,10 +600,10 @@ static ssize_t disksize_store(struct device *dev,
572600 goto out_free_meta ;
573601 }
574602
575- zram -> comp = zcomp_create (default_compressor , zram -> max_comp_streams );
603+ zram -> comp = zcomp_create (zram -> compressor , zram -> max_comp_streams );
576604 if (!zram -> comp ) {
577605 pr_info ("Cannot initialise %s compressing backend\n" ,
578- default_compressor );
606+ zram -> compressor );
579607 err = - EINVAL ;
580608 goto out_free_meta ;
581609 }
@@ -735,6 +763,8 @@ static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
735763static DEVICE_ATTR (mem_used_total , S_IRUGO , mem_used_total_show , NULL) ;
736764static DEVICE_ATTR (max_comp_streams , S_IRUGO | S_IWUSR ,
737765 max_comp_streams_show , max_comp_streams_store ) ;
766+ static DEVICE_ATTR (comp_algorithm , S_IRUGO | S_IWUSR ,
767+ comp_algorithm_show , comp_algorithm_store );
738768
739769ZRAM_ATTR_RO (num_reads );
740770ZRAM_ATTR_RO (num_writes );
@@ -760,6 +790,7 @@ static struct attribute *zram_disk_attrs[] = {
760790 & dev_attr_compr_data_size .attr ,
761791 & dev_attr_mem_used_total .attr ,
762792 & dev_attr_max_comp_streams .attr ,
793+ & dev_attr_comp_algorithm .attr ,
763794 NULL ,
764795};
765796
@@ -820,7 +851,7 @@ static int create_device(struct zram *zram, int device_id)
820851 pr_warn ("Error creating sysfs group" );
821852 goto out_free_disk ;
822853 }
823-
854+ strlcpy ( zram -> compressor , default_compressor , sizeof ( zram -> compressor ));
824855 zram -> meta = NULL ;
825856 zram -> max_comp_streams = 1 ;
826857 return 0 ;
0 commit comments