Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: zcache: remove zcache_direct_reclaim_lock

zcache_do_preload() currently does a spin_trylock() on the
zcache_direct_reclaim_lock. Holding this lock intends to prevent
shrink_zcache_memory() from evicting zbud pages as a result
of a preload.

However, it also prevents two threads from
executing zcache_do_preload() at the same time. The first
thread will obtain the lock and the second thread's spin_trylock()
will fail (an aborted preload) causing the page to be either lost
(cleancache) or pushed out to the swap device (frontswap). It
also doesn't ensure that the call to shrink_zcache_memory() is
on the same thread as the call to zcache_do_preload().

Additional, there is no need for this mechanism because all
zcache_do_preload() calls that come down from cleancache already
have PF_MEMALLOC set in the process flags which prevents
direct reclaim in the memory manager. If the zcache_do_preload()
call is done from the frontswap path, we _want_ reclaim to be
done (which it isn't right now).

This patch removes the zcache_direct_reclaim_lock and related
statistics in zcache.

Based on v3.1-rc8

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Reviewed-by: Dave Hansen <dave@linux.vnet.ibm.com>
Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Seth Jennings and committed by
Greg Kroah-Hartman
00bf2560 3b769edd

+4 -27
+4 -27
drivers/staging/zcache/zcache-main.c
··· 962 962 static unsigned long zcache_failed_get_free_pages; 963 963 static unsigned long zcache_failed_alloc; 964 964 static unsigned long zcache_put_to_flush; 965 - static unsigned long zcache_aborted_preload; 966 - static unsigned long zcache_aborted_shrink; 967 - 968 - /* 969 - * Ensure that memory allocation requests in zcache don't result 970 - * in direct reclaim requests via the shrinker, which would cause 971 - * an infinite loop. Maybe a GFP flag would be better? 972 - */ 973 - static DEFINE_SPINLOCK(zcache_direct_reclaim_lock); 974 965 975 966 /* 976 967 * for now, used named slabs so can easily track usage; later can ··· 1000 1009 goto out; 1001 1010 if (unlikely(zcache_obj_cache == NULL)) 1002 1011 goto out; 1003 - if (!spin_trylock(&zcache_direct_reclaim_lock)) { 1004 - zcache_aborted_preload++; 1005 - goto out; 1006 - } 1007 1012 preempt_disable(); 1008 1013 kp = &__get_cpu_var(zcache_preloads); 1009 1014 while (kp->nr < ARRAY_SIZE(kp->objnodes)) { ··· 1008 1021 ZCACHE_GFP_MASK); 1009 1022 if (unlikely(objnode == NULL)) { 1010 1023 zcache_failed_alloc++; 1011 - goto unlock_out; 1024 + goto out; 1012 1025 } 1013 1026 preempt_disable(); 1014 1027 kp = &__get_cpu_var(zcache_preloads); ··· 1021 1034 obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK); 1022 1035 if (unlikely(obj == NULL)) { 1023 1036 zcache_failed_alloc++; 1024 - goto unlock_out; 1037 + goto out; 1025 1038 } 1026 1039 page = (void *)__get_free_page(ZCACHE_GFP_MASK); 1027 1040 if (unlikely(page == NULL)) { 1028 1041 zcache_failed_get_free_pages++; 1029 1042 kmem_cache_free(zcache_obj_cache, obj); 1030 - goto unlock_out; 1043 + goto out; 1031 1044 } 1032 1045 preempt_disable(); 1033 1046 kp = &__get_cpu_var(zcache_preloads); ··· 1040 1053 else 1041 1054 free_page((unsigned long)page); 1042 1055 ret = 0; 1043 - unlock_out: 1044 - spin_unlock(&zcache_direct_reclaim_lock); 1045 1056 out: 1046 1057 return ret; 1047 1058 } ··· 1414 1429 ZCACHE_SYSFS_RO(failed_get_free_pages); 1415 1430 ZCACHE_SYSFS_RO(failed_alloc); 1416 1431 ZCACHE_SYSFS_RO(put_to_flush); 1417 - ZCACHE_SYSFS_RO(aborted_preload); 1418 - ZCACHE_SYSFS_RO(aborted_shrink); 1419 1432 ZCACHE_SYSFS_RO(compress_poor); 1420 1433 ZCACHE_SYSFS_RO(mean_compress_poor); 1421 1434 ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_raw_pages); ··· 1455 1472 &zcache_failed_get_free_pages_attr.attr, 1456 1473 &zcache_failed_alloc_attr.attr, 1457 1474 &zcache_put_to_flush_attr.attr, 1458 - &zcache_aborted_preload_attr.attr, 1459 - &zcache_aborted_shrink_attr.attr, 1460 1475 &zcache_zbud_unbuddied_list_counts_attr.attr, 1461 1476 &zcache_zbud_cumul_chunk_counts_attr.attr, 1462 1477 &zcache_zv_curr_dist_counts_attr.attr, ··· 1494 1513 if (!(gfp_mask & __GFP_FS)) 1495 1514 /* does this case really need to be skipped? */ 1496 1515 goto out; 1497 - if (spin_trylock(&zcache_direct_reclaim_lock)) { 1498 - zbud_evict_pages(nr); 1499 - spin_unlock(&zcache_direct_reclaim_lock); 1500 - } else 1501 - zcache_aborted_shrink++; 1516 + zbud_evict_pages(nr); 1502 1517 } 1503 1518 ret = (int)atomic_read(&zcache_zbud_curr_raw_pages); 1504 1519 out: