From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754828AbcEWMMe (ORCPT ); Mon, 23 May 2016 08:12:34 -0400 Received: from mail-db3on0110.outbound.protection.outlook.com ([157.55.234.110]:50878 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754775AbcEWMMc (ORCPT ); Mon, 23 May 2016 08:12:32 -0400 X-Greylist: delayed 4748 seconds by postgrey-1.27 at vger.kernel.org; Mon, 23 May 2016 08:12:31 EDT Authentication-Results: linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=none action=none header.from=virtuozzo.com; Date: Mon, 23 May 2016 14:57:19 +0300 From: Vladimir Davydov To: Andrew Morton CC: Alexander Viro , Johannes Weiner , Michal Hocko , , Subject: Re: [PATCH 7/8] pipe: account to kmemcg Message-ID: <20160523115719.GF7917@esperanza> References: <9e5dd7673dc37f198615b717fb1eae9309115134.1463997354.git.vdavydov@virtuozzo.com> <201605231850.3CoT8OXo%fengguang.wu@intel.com> <20160523105718.GC7917@esperanza> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20160523105718.GC7917@esperanza> X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AMSPR02CA0048.eurprd02.prod.outlook.com (2a01:111:e400:8028::48) To AM3PR08MB0579.eurprd08.prod.outlook.com (2a01:111:e400:c408::13) X-MS-Office365-Filtering-Correlation-Id: e6f5cf8b-67cf-4aa7-cb91-08d38301668f X-Microsoft-Exchange-Diagnostics: 1;AM3PR08MB0579;2:wSfHg6RbDNX0W5l6/p029fUGLluurZmabsfg/zOS7ThqnB1SMolVWNcN9NgdfnC+ZpOhUaqOrGnDUzz4D9dn6JNg5s2VSCsgzpaM81dXVlNt+wwrmELg0Nh/fNrmw1xfooyHSPinISL6u9ANWisrAt8nVxlrGhIa7/MehyCDjGNd0Pl2lWAprVS9uRpoimar;3:y3+SUhELBywaPxDjcHmU46lRudtn+ISTkSs5usKWtrd886zESb0MeyQ/qoZegVZq/uJymGgFwdSOfefqW9vigKgV3HJztZbLqtqNidwfZNjPKQFz9wZiF3DPYSbwE8Ev X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM3PR08MB0579; X-Microsoft-Exchange-Diagnostics: 1;AM3PR08MB0579;25:e4CgBhLU7MdKrcuev4w9m8xWT7JwIJpJNB2t5Y6kWwdfUGlWoYIjnRq7Hb4zQRrdPwx95nM5a89SYwbIYPnqcpiBY1A3cExHZ/a24gvJ8KCPwJjkZ9hmbn5EA3egee5qdkLwzknfDVZTQRlFKTGlOw/Hma16W5wGFPPUl4Jr4clh0dXV1WHTX55NvzJzGkom9OPrfCpviLdPcacOlcUhWUCixZWuC7ruj3kPnbArxrDR5YEWvW2VErCshrm4EvjfUxXvHEbNcI+rqXlNzmVgoLqvEBYLdnbblRrCtQVWib2eL+ReMJd8Wc9reG8bm/YwmJWDXlCjcuFYYC57MU8aagD8dkLsuTUZqz5ew6rBIXXJKEouJmR4mN9zJJQag9o+OVR7k5SyXF4kdia/B2qovHRqdYXMfDGxQxBsgozWVnrHqgTmY1vd07Vzv1LLHxTIBQBYrCZZSSTt7DyCJLTOFTRDIL9Wc79Iv/MOGKYxREa0tCzXiPHQfVcGhko623TEy5y8iAoLVQH3LpDCVvDmjy8DCwj++pnp0m+CpMhhJ2JrxLnaAUh0mFV50zH+YuHZdceSqYSxUxgz+5dfo7Q+qDVlgQoFfvbj7xRiD6UocCGlJD4t1RpkxsAmD2AzwZ6jmUSjFUo2wlYvXc9dHscLsJ4L5N2UiSDlhUsKpmMKkOJ5X3/9ChSMVO5mPftXSZL1enJHCF4BPS0/XHTaP4jHry2EA4fqEH7eJxNluwJdhWJPfa7k9jrihbHU9vVaMMFK X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040130)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041072)(6043046);SRVR:AM3PR08MB0579;BCL:0;PCL:0;RULEID:;SRVR:AM3PR08MB0579; X-Microsoft-Exchange-Diagnostics: 1;AM3PR08MB0579;4:AAX5owdy3BxfMYpTYwbiyAI6XF/+YPHXzD5gTPRXmp/wDSciacxpDnrzbPe8TjLXEH7Mt2Bd6MwK7O7pzBRZ1Yoj/pfGtm3Wy3scbVS9gVuhkLL1tGC1ttlayjnByytzKKZGWYypydyp6zeNDq3oeC9FJ29Qo8h9OLZotaJsdeybrl0dUo3GDSXMjzYlnUZphsMhXjemMhP9UjyG1jiVJnQCLEhgwonPgarVIQuDInSe/jFfLSDI4gDnUJ7dBwHsOejvDWx2JZrMn0g3k295pG/z0gTH0ZoKPkjAVBkCYQc8wOvXTnv43ujXEXXPzTJP6i0jKo84YlXZOZ2UfbschL7KeuIiPLShmaRX0FRPDU/yBZgEntrngTUmaodw5Mm5qIw++7rohFjxMSUR+Sy/blh8wJ8t/333NxmrkwCTEvM= X-Forefront-PRVS: 0951AB0A30 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(24454002)(6116002)(3846002)(1076002)(19580405001)(8676002)(23726003)(19580395003)(586003)(80792005)(46406003)(42186005)(76176999)(92566002)(86362001)(9686002)(110136002)(189998001)(4326007)(2906002)(15650500001)(575784001)(81166006)(5008740100001)(66066001)(2950100001)(33656002)(47776003)(50986999)(54356999)(97756001)(33716001)(5004730100002)(50466002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM3PR08MB0579;H:esperanza;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM3PR08MB0579;23:IAOFXjq+tjxgqsZu3eOdg/c0S9FIi165z3ZwRsxk7?= =?us-ascii?Q?th1XLlKW1ulyvK9iLYnMQwrbB/JJPho0sDAHnCVV8EhMWH+LNZijx/FrQ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UFoQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM3PR08MB0579;5:P0uAXZ+RTfhC+aymwz78dIDJdwlwfGAcpQF9H5ETR0mVIRz7u+yLXs4rkG2qOUt+jg1H3OY7Yw9mT7hxrp7HFpeRVb7UhKATPYBFQHixaqIvYUx/KvMJzqErZm0WnaZcKq0JIvyNAOSZl9Tinzw7og==;24:ZzvPNzcqnnO9iJCmoVOdYYBfGBwzoc462hOSFrqS3R+svSfjHbRgHlOffYhUZOXJ/y7/XUqkom6Q0mF46Q1Y410bDW8rsm92mguVBEYlMaI=;7:4SUEK1TByUs2v0Z44ZEmQM1JGgmr/000eJL7cKNnX7GXk2Fc1Gu/2ZTl9XRq4C1Y0TfJBewvrEEiqe7LVJJzHZmr5A7H5L5fz/A4EuVTcQnrqkK2/3wYKbBTz8eI2Lll2hU6MX5L/JBqDEovbVxl295aHgR8RgEWowcyYyzMPSmGNVHPjMvRnnOdWIVsjg4Q;20:CPS2FjiTD5ApwTYxAiU4sFP8tjeoFivntQOzqAtZiNWLhKp6/u2SxTCzGAd3UPsZBqlpzhnRHMYTjoOhdSSIU7pyGX4fiiyPacIBaV1vdBIYqGkXTNVaTq0WTIRyuK1dwOJ3i79L/LNTVCjRiL4mU/TH4gtxWC9OS8yxNRQK834= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2016 11:57:22.1714 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0579 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2016 at 01:57:18PM +0300, Vladimir Davydov wrote: > Subject: [PATCH] pipe-account-to-kmemcg-fix Darn it, I missed kcalloc in pipe_set_size. Below goes a full version of this particular patch with both fixes incorporated. Sorry for the noise. -- From: Vladimir Davydov Subject: [PATCH] pipe: account to kmemcg Pipes can consume a significant amount of system memory, hence they should be accounted to kmemcg. This patch marks pipe_inode_info and anonymous pipe buffer page allocations as __GFP_ACCOUNT so that they would be charged to kmemcg. Note, since a pipe buffer page can be "stolen" and get reused for other purposes, including mapping to userspace, we clear PageKmemcg thus resetting page->_mapcount and uncharge it in anon_pipe_buf_steal, which is introduced by this patch. Signed-off-by: Vladimir Davydov Cc: Alexander Viro diff --git a/fs/pipe.c b/fs/pipe.c index 0d3f5165cb0b..4b32928f5426 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -137,6 +138,22 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe, put_page(page); } +static int anon_pipe_buf_steal(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ + struct page *page = buf->page; + + if (page_count(page) == 1) { + if (memcg_kmem_enabled()) { + memcg_kmem_uncharge(page, 0); + __ClearPageKmemcg(page); + } + __SetPageLocked(page); + return 0; + } + return 1; +} + /** * generic_pipe_buf_steal - attempt to take ownership of a &pipe_buffer * @pipe: the pipe that the buffer belongs to @@ -219,7 +236,7 @@ static const struct pipe_buf_operations anon_pipe_buf_ops = { .can_merge = 1, .confirm = generic_pipe_buf_confirm, .release = anon_pipe_buf_release, - .steal = generic_pipe_buf_steal, + .steal = anon_pipe_buf_steal, .get = generic_pipe_buf_get, }; @@ -227,7 +244,7 @@ static const struct pipe_buf_operations packet_pipe_buf_ops = { .can_merge = 0, .confirm = generic_pipe_buf_confirm, .release = anon_pipe_buf_release, - .steal = generic_pipe_buf_steal, + .steal = anon_pipe_buf_steal, .get = generic_pipe_buf_get, }; @@ -405,7 +422,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) int copied; if (!page) { - page = alloc_page(GFP_HIGHUSER); + page = alloc_page(GFP_HIGHUSER | __GFP_ACCOUNT); if (unlikely(!page)) { ret = ret ? : -ENOMEM; break; @@ -611,7 +628,7 @@ struct pipe_inode_info *alloc_pipe_info(void) { struct pipe_inode_info *pipe; - pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL); + pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL_ACCOUNT); if (pipe) { unsigned long pipe_bufs = PIPE_DEF_BUFFERS; struct user_struct *user = get_current_user(); @@ -619,7 +636,9 @@ struct pipe_inode_info *alloc_pipe_info(void) if (!too_many_pipe_buffers_hard(user)) { if (too_many_pipe_buffers_soft(user)) pipe_bufs = 1; - pipe->bufs = kzalloc(sizeof(struct pipe_buffer) * pipe_bufs, GFP_KERNEL); + pipe->bufs = kcalloc(pipe_bufs, + sizeof(struct pipe_buffer), + GFP_KERNEL_ACCOUNT); } if (pipe->bufs) { @@ -1010,7 +1029,8 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages) if (nr_pages < pipe->nrbufs) return -EBUSY; - bufs = kcalloc(nr_pages, sizeof(*bufs), GFP_KERNEL | __GFP_NOWARN); + bufs = kcalloc(nr_pages, sizeof(*bufs), + GFP_KERNEL_ACCOUNT | __GFP_NOWARN); if (unlikely(!bufs)) return -ENOMEM;