Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp131653imu; Mon, 26 Nov 2018 18:14:24 -0800 (PST) X-Google-Smtp-Source: AJdET5cSmTLUHSUQcqPYI6x1teUdAUqZhb4GEz6ZWG0T1QgR4sUq4l1jfyvigOqZxGzOTrfs77MQ X-Received: by 2002:a62:2cf:: with SMTP id 198mr30059866pfc.67.1543284864546; Mon, 26 Nov 2018 18:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543284864; cv=none; d=google.com; s=arc-20160816; b=jmY3ule9qm2jLQGcr5twgPVvxMW8Dov37G/Dyj6+h9chdU9Yb7H7my0iajS+M4kuVO QMSwAtxhnFebBnn+MuVPoJR23y+JCGMxAUOMQiwuIAWcdMCuMxDKwU4N4YmTJJPJ7ogn bx3NAUQ/KL7UbRTd0QB9Iay2mhwMvN90MixZN28LUzY/6nknNFiOdHo6rK9Zk+D9oqBt fbzH/755q5YbLcxnQGNTEItIl3ZjitbBGlsOyZy1VpeV0FttNsWsOUOE3qb5NlevZ0mD cxxBAM5+IeKGz2NCxxOXZ8OwYxZbFjx/D4zpLC+nEtokQRMYxk02o+RjpCbBb+pkXdfL jUTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dkim-signature; bh=C2Pt8xP9+WD8GP/Q4gOyb9TqFHid8wy+SDEEJjPCdmc=; b=EOyidBYHgnsrTfAyrBZ2UTy0GrDG6jC0ExfalAS5Lhmu0WJZAXqxDCDyNOuFb20Vsd 721yuBznNqVnteEcDHRDUG3BUeWDrRsrC+auRy0b77n6Pnza+B26bsKbdLJryNTLZ70K aq7fWXtftlRJxfOIqFZ0EZjHXnceEsihOtafR+nhL+gswIClyFkWgMCr8m+A6mO8iQwb auYBqK3dsOu5FurpuMkH3Sh/yFBr5/fHVLEQS0Hp4QkR0gs2tCVPU4XvTZXROCAwz+OK hN4hHQHl6dRR6Z1zj3/4W97G2CRSLhhCniPMB/3itVJRmzEzqqU5fxD1Jvm2VAo8ldru EnAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ntfgGhmJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si2042862pgk.201.2018.11.26.18.14.09; Mon, 26 Nov 2018 18:14:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ntfgGhmJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728170AbeK0NJr (ORCPT + 99 others); Tue, 27 Nov 2018 08:09:47 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40163 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727552AbeK0NJr (ORCPT ); Tue, 27 Nov 2018 08:09:47 -0500 Received: by mail-pf1-f195.google.com with SMTP id i12so7548601pfo.7 for ; Mon, 26 Nov 2018 18:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=C2Pt8xP9+WD8GP/Q4gOyb9TqFHid8wy+SDEEJjPCdmc=; b=ntfgGhmJKQUqN/eOB3XK7rnFNWIbajNvWa7/tTeuwnZ6Y9fGAYLoanXg5P1zaur7Ch +zOM3RlbRRWG4vhjfiuRI7kyUAGd+uxVkM9zxRRiiUdaORvEarGQG8hkxRYdtYoAqllt BAHxM6ITDcoEFc1NNy1DLDuyaTKWdhpIXMU4kPGvdeTlBM1bUhenGQSe2XOqXLxcdbWf ECngFcozsxttRYSAEtJjg5rtUqmaq6MbDXesvdIpOJaFRdgRSmAM0lYjq75/TlsLZyN3 DCw7/liULzPiww8MYQoxmNM08j+XzUrGHdY1Ns7IIKJfaDTstpnUqXd/Zcd4NvtsHDYG c3Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=C2Pt8xP9+WD8GP/Q4gOyb9TqFHid8wy+SDEEJjPCdmc=; b=YvxpvPpg6NBv41aeqW0izB6/Mb4+ykfe+OU4eszuzOxh/at9CsCsCOpON6dFEz2zE9 vLZBhWQj7oIzWX+3aiiJCungIyXxIhkljwfCv46pP78TmlPNw1XPdFK9vFLlrkWri8zr U0UrUwvDKx7mxeWNlRzVDtUv8ZclfKkIo/lRM5Muqua+u3DkX6iI1AUQYTrGJBLqzIlm FI14sKraI4e+iRK6jYOANwRsc18drxm5ZHso9bUfT4tr4CWqw/r/4JO0Yrex0yP0J2eG +JBShZL96ignb3DqlGfHMUG8BFu4E0QWaRJjyz6Qv3NLpdzYiaolF9FliQohrnLTStCT ydhw== X-Gm-Message-State: AA+aEWZmIDEN7o1yZdlWPhswnlvd5MqUCdxMhMMZ4dKhbzStWYHC6OVD rBOu6I7TiBr6blbYj5V4TSOanyfJ4Tk= X-Received: by 2002:a63:2141:: with SMTP id s1mr27597802pgm.148.1543284812357; Mon, 26 Nov 2018 18:13:32 -0800 (PST) Received: from google.com ([2401:fa00:d:0:98f1:8b3d:1f37:3e8]) by smtp.gmail.com with ESMTPSA id z62sm2980204pfi.4.2018.11.26.18.13.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Nov 2018 18:13:31 -0800 (PST) Date: Tue, 27 Nov 2018 11:13:27 +0900 From: Minchan Kim To: Joey Pabalinas , Andrew Morton , LKML , Sergey Senozhatsky Subject: Re: [PATCH v2 5/7] zram: support idle/huge page writeback Message-ID: <20181127021327.GD237537@google.com> References: <20181126082813.81977-1-minchan@kernel.org> <20181126082813.81977-6-minchan@kernel.org> <20181126094737.sfudpeoigra2vir7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181126094737.sfudpeoigra2vir7@gmail.com> User-Agent: Mutt/1.10.1+60 (6df12dc1) (2018-08-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 25, 2018 at 11:47:37PM -1000, Joey Pabalinas wrote: > On Mon, Nov 26, 2018 at 05:28:11PM +0900, Minchan Kim wrote: > > + strlcpy(mode_buf, buf, sizeof(mode_buf)); > > + /* ignore trailing newline */ > > + sz = strlen(mode_buf); > > One possible idea would be to use strscpy() instead and directly assign > the return value to sz, avoiding an extra strlen() call (though you would > have to check if `sz == -E2BIG` and do `sz = sizeof(mode_buf) - 1` in that > case). Thanks for the suggstion. If I limit destination buffer smaller, I couldn't meet -E2BIG? > > > + if (!strcmp(mode_buf, "idle")) > > + mode = IDLE_WRITEBACK; > > + if (!strcmp(mode_buf, "huge")) > > + mode = HUGE_WRITEBACK; > > Maybe using `else if (!strcmp(mode_buf, "huge"))` would be slightly > better here, avoiding a second strcmp() if mode_buf has already > matched "idle". I considered "huge|idle" as an option. Anyway, in that case, mode should "mode |= ". At this moment, yes, lets use "else if" since I don't have strong opinion to support "idle|huge". > > > + if ((mode & IDLE_WRITEBACK && > > + !zram_test_flag(zram, index, ZRAM_IDLE)) && > > + (mode & HUGE_WRITEBACK && > > + !zram_test_flag(zram, index, ZRAM_HUGE))) > > + goto next; > > Wouldn't writing this as `mode & (IDLE_WRITEBACK | HUGE_WRITEBACK)` > be a bit easier to read as well as slightly more compact? > > > + ret = len; > > + __free_page(page); > > +release_init_lock: > > + up_read(&zram->init_lock); > > + return ret; > > Hm, I noticed that this function either returns an error or just the passed > in len on success, and I'm left wondering if there might be other useful > information which could be passed back to the caller instead. I can't > immediately think of any such information, though, so it's possible I'm > just daydreaming :) It is write syscall semantic of sysfs so not sure it's doable to pass other value to user. > > -- > Cheers, > Joey Pabalinas