@@ -112,19 +112,19 @@ static inline int clip_level(int level)
112
112
*/
113
113
static void zstd_reclaim_timer_fn (struct timer_list * timer )
114
114
{
115
+ struct zstd_workspace_manager * zwsm =
116
+ container_of (timer , struct zstd_workspace_manager , timer );
115
117
unsigned long reclaim_threshold = jiffies - ZSTD_BTRFS_RECLAIM_JIFFIES ;
116
118
struct list_head * pos , * next ;
117
119
118
- ASSERT ( timer == & wsm . timer );
120
+ spin_lock ( & zwsm -> lock );
119
121
120
- spin_lock (& wsm .lock );
121
-
122
- if (list_empty (& wsm .lru_list )) {
123
- spin_unlock (& wsm .lock );
122
+ if (list_empty (& zwsm -> lru_list )) {
123
+ spin_unlock (& zwsm -> lock );
124
124
return ;
125
125
}
126
126
127
- list_for_each_prev_safe (pos , next , & wsm . lru_list ) {
127
+ list_for_each_prev_safe (pos , next , & zwsm -> lru_list ) {
128
128
struct workspace * victim = container_of (pos , struct workspace ,
129
129
lru_list );
130
130
int level ;
@@ -141,15 +141,15 @@ static void zstd_reclaim_timer_fn(struct timer_list *timer)
141
141
list_del (& victim -> list );
142
142
zstd_free_workspace (& victim -> list );
143
143
144
- if (list_empty (& wsm . idle_ws [level ]))
145
- clear_bit (level , & wsm . active_map );
144
+ if (list_empty (& zwsm -> idle_ws [level ]))
145
+ clear_bit (level , & zwsm -> active_map );
146
146
147
147
}
148
148
149
- if (!list_empty (& wsm . lru_list ))
150
- mod_timer (& wsm . timer , jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES );
149
+ if (!list_empty (& zwsm -> lru_list ))
150
+ mod_timer (& zwsm -> timer , jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES );
151
151
152
- spin_unlock (& wsm . lock );
152
+ spin_unlock (& zwsm -> lock );
153
153
}
154
154
155
155
/*
@@ -292,29 +292,31 @@ void zstd_cleanup_workspace_manager(void)
292
292
* offer the opportunity to reclaim the workspace in favor of allocating an
293
293
* appropriately sized one in the future.
294
294
*/
295
- static struct list_head * zstd_find_workspace (int level )
295
+ static struct list_head * zstd_find_workspace (struct btrfs_fs_info * fs_info , int level )
296
296
{
297
+ struct zstd_workspace_manager * zwsm = fs_info -> compr_wsm [BTRFS_COMPRESS_ZSTD ];
297
298
struct list_head * ws ;
298
299
struct workspace * workspace ;
299
300
int i = clip_level (level );
300
301
301
- spin_lock_bh (& wsm .lock );
302
- for_each_set_bit_from (i , & wsm .active_map , ZSTD_BTRFS_MAX_LEVEL ) {
303
- if (!list_empty (& wsm .idle_ws [i ])) {
304
- ws = wsm .idle_ws [i ].next ;
302
+ ASSERT (zwsm );
303
+ spin_lock_bh (& zwsm -> lock );
304
+ for_each_set_bit_from (i , & zwsm -> active_map , ZSTD_BTRFS_MAX_LEVEL ) {
305
+ if (!list_empty (& zwsm -> idle_ws [i ])) {
306
+ ws = zwsm -> idle_ws [i ].next ;
305
307
workspace = list_to_workspace (ws );
306
308
list_del_init (ws );
307
309
/* keep its place if it's a lower level using this */
308
310
workspace -> req_level = level ;
309
311
if (clip_level (level ) == workspace -> level )
310
312
list_del (& workspace -> lru_list );
311
- if (list_empty (& wsm . idle_ws [i ]))
312
- clear_bit (i , & wsm . active_map );
313
- spin_unlock_bh (& wsm . lock );
313
+ if (list_empty (& zwsm -> idle_ws [i ]))
314
+ clear_bit (i , & zwsm -> active_map );
315
+ spin_unlock_bh (& zwsm -> lock );
314
316
return ws ;
315
317
}
316
318
}
317
- spin_unlock_bh (& wsm . lock );
319
+ spin_unlock_bh (& zwsm -> lock );
318
320
319
321
return NULL ;
320
322
}
@@ -331,15 +333,18 @@ static struct list_head *zstd_find_workspace(int level)
331
333
*/
332
334
struct list_head * zstd_get_workspace (struct btrfs_fs_info * fs_info , int level )
333
335
{
336
+ struct zstd_workspace_manager * zwsm = fs_info -> compr_wsm [BTRFS_COMPRESS_ZSTD ];
334
337
struct list_head * ws ;
335
338
unsigned int nofs_flag ;
336
339
340
+ ASSERT (zwsm );
341
+
337
342
/* level == 0 means we can use any workspace */
338
343
if (!level )
339
344
level = 1 ;
340
345
341
346
again :
342
- ws = zstd_find_workspace (level );
347
+ ws = zstd_find_workspace (fs_info , level );
343
348
if (ws )
344
349
return ws ;
345
350
@@ -350,9 +355,9 @@ struct list_head *zstd_get_workspace(struct btrfs_fs_info *fs_info, int level)
350
355
if (IS_ERR (ws )) {
351
356
DEFINE_WAIT (wait );
352
357
353
- prepare_to_wait (& wsm . wait , & wait , TASK_UNINTERRUPTIBLE );
358
+ prepare_to_wait (& zwsm -> wait , & wait , TASK_UNINTERRUPTIBLE );
354
359
schedule ();
355
- finish_wait (& wsm . wait , & wait );
360
+ finish_wait (& zwsm -> wait , & wait );
356
361
357
362
goto again ;
358
363
}
@@ -373,32 +378,34 @@ struct list_head *zstd_get_workspace(struct btrfs_fs_info *fs_info, int level)
373
378
*/
374
379
void zstd_put_workspace (struct btrfs_fs_info * fs_info , struct list_head * ws )
375
380
{
381
+ struct zstd_workspace_manager * zwsm = fs_info -> compr_wsm [BTRFS_COMPRESS_ZSTD ];
376
382
struct workspace * workspace = list_to_workspace (ws );
377
383
378
- spin_lock_bh (& wsm .lock );
384
+ ASSERT (zwsm );
385
+ spin_lock_bh (& zwsm -> lock );
379
386
380
387
/* A node is only taken off the lru if we are the corresponding level */
381
388
if (clip_level (workspace -> req_level ) == workspace -> level ) {
382
389
/* Hide a max level workspace from reclaim */
383
- if (list_empty (& wsm . idle_ws [ZSTD_BTRFS_MAX_LEVEL - 1 ])) {
390
+ if (list_empty (& zwsm -> idle_ws [ZSTD_BTRFS_MAX_LEVEL - 1 ])) {
384
391
INIT_LIST_HEAD (& workspace -> lru_list );
385
392
} else {
386
393
workspace -> last_used = jiffies ;
387
- list_add (& workspace -> lru_list , & wsm . lru_list );
388
- if (!timer_pending (& wsm . timer ))
389
- mod_timer (& wsm . timer ,
394
+ list_add (& workspace -> lru_list , & zwsm -> lru_list );
395
+ if (!timer_pending (& zwsm -> timer ))
396
+ mod_timer (& zwsm -> timer ,
390
397
jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES );
391
398
}
392
399
}
393
400
394
- set_bit (workspace -> level , & wsm . active_map );
395
- list_add (& workspace -> list , & wsm . idle_ws [workspace -> level ]);
401
+ set_bit (workspace -> level , & zwsm -> active_map );
402
+ list_add (& workspace -> list , & zwsm -> idle_ws [workspace -> level ]);
396
403
workspace -> req_level = 0 ;
397
404
398
- spin_unlock_bh (& wsm . lock );
405
+ spin_unlock_bh (& zwsm -> lock );
399
406
400
407
if (workspace -> level == clip_level (ZSTD_BTRFS_MAX_LEVEL ))
401
- cond_wake_up (& wsm . wait );
408
+ cond_wake_up (& zwsm -> wait );
402
409
}
403
410
404
411
void zstd_free_workspace (struct list_head * ws )
0 commit comments