@@ -148,8 +148,7 @@ void ttm_tt_destroy_common(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
148148{
149149 ttm_tt_unpopulate (bdev , ttm );
150150
151- if (!(ttm -> page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP ) &&
152- ttm -> swap_storage )
151+ if (ttm -> swap_storage )
153152 fput (ttm -> swap_storage );
154153
155154 ttm -> swap_storage = NULL ;
@@ -249,71 +248,67 @@ int ttm_tt_swapin(struct ttm_tt *ttm)
249248 struct file * swap_storage ;
250249 struct page * from_page ;
251250 struct page * to_page ;
252- int i ;
253- int ret = - ENOMEM ;
251+ gfp_t gfp_mask ;
252+ int i , ret ;
254253
255254 swap_storage = ttm -> swap_storage ;
256255 BUG_ON (swap_storage == NULL );
257256
258257 swap_space = swap_storage -> f_mapping ;
258+ gfp_mask = mapping_gfp_mask (swap_space );
259+ if (ttm -> page_flags & TTM_PAGE_FLAG_NO_RETRY )
260+ gfp_mask |= __GFP_RETRY_MAYFAIL ;
259261
260262 for (i = 0 ; i < ttm -> num_pages ; ++ i ) {
261- gfp_t gfp_mask = mapping_gfp_mask (swap_space );
262-
263- gfp_mask |= (ttm -> page_flags & TTM_PAGE_FLAG_NO_RETRY ? __GFP_RETRY_MAYFAIL : 0 );
264- from_page = shmem_read_mapping_page_gfp (swap_space , i , gfp_mask );
265-
263+ from_page = shmem_read_mapping_page_gfp (swap_space , i ,
264+ gfp_mask );
266265 if (IS_ERR (from_page )) {
267266 ret = PTR_ERR (from_page );
268267 goto out_err ;
269268 }
270269 to_page = ttm -> pages [i ];
271- if (unlikely (to_page == NULL ))
270+ if (unlikely (to_page == NULL )) {
271+ ret = - ENOMEM ;
272272 goto out_err ;
273+ }
273274
274275 copy_highpage (to_page , from_page );
275276 put_page (from_page );
276277 }
277278
278- if (!(ttm -> page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP ))
279- fput (swap_storage );
279+ fput (swap_storage );
280280 ttm -> swap_storage = NULL ;
281281 ttm -> page_flags &= ~TTM_PAGE_FLAG_SWAPPED ;
282282
283283 return 0 ;
284+
284285out_err :
285286 return ret ;
286287}
287288
288- int ttm_tt_swapout (struct ttm_bo_device * bdev ,
289- struct ttm_tt * ttm , struct file * persistent_swap_storage )
289+ int ttm_tt_swapout (struct ttm_bo_device * bdev , struct ttm_tt * ttm )
290290{
291291 struct address_space * swap_space ;
292292 struct file * swap_storage ;
293293 struct page * from_page ;
294294 struct page * to_page ;
295- int i ;
296- int ret = - ENOMEM ;
297-
298- if (!persistent_swap_storage ) {
299- swap_storage = shmem_file_setup ("ttm swap" ,
300- ttm -> num_pages << PAGE_SHIFT ,
301- 0 );
302- if (IS_ERR (swap_storage )) {
303- pr_err ("Failed allocating swap storage\n" );
304- return PTR_ERR (swap_storage );
305- }
306- } else {
307- swap_storage = persistent_swap_storage ;
295+ gfp_t gfp_mask ;
296+ int i , ret ;
297+
298+ swap_storage = shmem_file_setup ("ttm swap" ,
299+ ttm -> num_pages << PAGE_SHIFT ,
300+ 0 );
301+ if (IS_ERR (swap_storage )) {
302+ pr_err ("Failed allocating swap storage\n" );
303+ return PTR_ERR (swap_storage );
308304 }
309305
310306 swap_space = swap_storage -> f_mapping ;
307+ gfp_mask = mapping_gfp_mask (swap_space );
308+ if (ttm -> page_flags & TTM_PAGE_FLAG_NO_RETRY )
309+ gfp_mask |= __GFP_RETRY_MAYFAIL ;
311310
312311 for (i = 0 ; i < ttm -> num_pages ; ++ i ) {
313- gfp_t gfp_mask = mapping_gfp_mask (swap_space );
314-
315- gfp_mask |= (ttm -> page_flags & TTM_PAGE_FLAG_NO_RETRY ? __GFP_RETRY_MAYFAIL : 0 );
316-
317312 from_page = ttm -> pages [i ];
318313 if (unlikely (from_page == NULL ))
319314 continue ;
@@ -332,13 +327,11 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev,
332327 ttm_tt_unpopulate (bdev , ttm );
333328 ttm -> swap_storage = swap_storage ;
334329 ttm -> page_flags |= TTM_PAGE_FLAG_SWAPPED ;
335- if (persistent_swap_storage )
336- ttm -> page_flags |= TTM_PAGE_FLAG_PERSISTENT_SWAP ;
337330
338331 return 0 ;
332+
339333out_err :
340- if (!persistent_swap_storage )
341- fput (swap_storage );
334+ fput (swap_storage );
342335
343336 return ret ;
344337}
0 commit comments