Skip to content

Commit

Permalink
sunrpc: make the cache cleaner workqueue deferrable
Browse files Browse the repository at this point in the history
This patch makes the cache_cleaner workqueue deferrable, to prevent
unnecessary system wake-ups, which is very important for embedded
battery-powered devices.

do_cache_clean() is called every 30 seconds at the moment, and often
makes the system wake up from its power-save sleep state. With this
change, when the workqueue uses a deferrable timer, the
do_cache_clean() invocation will be delayed and combined with the
closest "real" wake-up. This improves the power consumption situation.

Note, I tried to create a DECLARE_DELAYED_WORK_DEFERRABLE() helper
macro, similar to DECLARE_DELAYED_WORK(), but failed because of the
way the timer wheel core stores the deferrable flag (it is the
LSBit in the time->base pointer). My attempt to define a static
variable with this bit set ended up with the "initializer element is
not constant" error.

Thus, I have to use run-time initialization, so I created a new
cache_initialize() function which is called once when sunrpc is
being initialized.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
  • Loading branch information
Artem Bityutskiy authored and J. Bruce Fields committed Jul 6, 2010
1 parent cba9ba4 commit 8eab945
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/linux/sunrpc/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ extern int cache_check(struct cache_detail *detail,
extern void cache_flush(void);
extern void cache_purge(struct cache_detail *detail);
#define NEVER (0x7FFFFFFF)
extern void __init cache_initialize(void);
extern int cache_register(struct cache_detail *cd);
extern void cache_unregister(struct cache_detail *cd);

Expand Down
7 changes: 6 additions & 1 deletion net/sunrpc/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static struct cache_detail *current_detail;
static int current_index;

static void do_cache_clean(struct work_struct *work);
static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean);
static struct delayed_work cache_cleaner;

static void sunrpc_init_cache_detail(struct cache_detail *cd)
{
Expand Down Expand Up @@ -1504,6 +1504,11 @@ static int create_cache_proc_entries(struct cache_detail *cd)
}
#endif

void __init cache_initialize(void)
{
INIT_DELAYED_WORK_DEFERRABLE(&cache_cleaner, do_cache_clean);
}

int cache_register(struct cache_detail *cd)
{
int ret;
Expand Down
1 change: 1 addition & 0 deletions net/sunrpc/sunrpc_syms.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ init_sunrpc(void)
#ifdef CONFIG_PROC_FS
rpc_proc_init();
#endif
cache_initialize();
cache_register(&ip_map_cache);
cache_register(&unix_gid_cache);
svc_init_xprt_sock(); /* svc sock transport */
Expand Down

0 comments on commit 8eab945

Please sign in to comment.