Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3901412pxy; Mon, 26 Apr 2021 12:31:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkqt9CbGv709CEpdkdm9E/uFqkKB5TeWA5GFW0W3FU64FM9L5lBFdMdR4kGEThX2zxolO0 X-Received: by 2002:a63:a47:: with SMTP id z7mr18021859pgk.350.1619465506176; Mon, 26 Apr 2021 12:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619465506; cv=none; d=google.com; s=arc-20160816; b=XCaUU0r63X9JmNFBnNnfSxcFjUnX/AXFcMof2OEagiMO3QfzGOqy/NPYw3GxMaw+OD biJ6xARJ9I7tPlQGzV3AB1zSO6+qqEyMReUFOTaBt/Qk/ECwMO+GUejOJjl0hYaOZw3d J5ffsTLL+DyRsbGi4BM1jhMdCaDmruLw1G/tozldRbyBdsTIC1W+hdUvNXkIBXAY4O4J APIi/5SOjVOC5UBL/8gPGYV5TUBVNNfostu1zmDkOzfBq6J3ilApzVv7YOodjss1ehnO zv0ixprVNKU2bQ6Pdrmvqw092BDIkwSgXf+KqJEdHKP6TjdI8i8qdMcCzsjreyfAGI4+ fVjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=r1+fehePF1LQa+ETT3QS1bc9x/S6CdwPnRCT51uHUm4=; b=qS3pvZ9yNDvuRJ39cn/+7IYItAxyzrhg/EEM6HzU7Nky8T0kzUDJjCYL5Su1Z1iaNF qlxqaft2rXnALSxBAMJbJlpaS+ClZxMeuxq1lSLa9ZDMVvzgNJ1nj1wvt6tSj0vlw9Tn DWrMZ5RemjLMWDZ105dBHsyu67t1JQO2MHcyhGH0nJp7noaqOFw7zc5k+fc+03TsOX7o MnBUW8qFYafmFW1vh9sMGZa+NpDDoHowCQYjJWpQztb+bp+tWoCY4kTYRWkSYsKDvWIF OxDwWtDMv9sCbID2sbjjK8HNdY3cOnOUeCG7aIQmc06Jyl7eJm3ZrjjSKgsY4z1SF+HQ AwZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Iap4Uo88; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 3si17759048pgk.246.2021.04.26.12.31.33; Mon, 26 Apr 2021 12:31:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Iap4Uo88; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240275AbhDZTY7 (ORCPT + 99 others); Mon, 26 Apr 2021 15:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240250AbhDZTY6 (ORCPT ); Mon, 26 Apr 2021 15:24:58 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E96BC061756 for ; Mon, 26 Apr 2021 12:24:15 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id z13so8957898lft.1 for ; Mon, 26 Apr 2021 12:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r1+fehePF1LQa+ETT3QS1bc9x/S6CdwPnRCT51uHUm4=; b=Iap4Uo88x+wPaxUmMexmQyhYyjf2sL25rylbPddEu+U/hlOmwkIefEtnY9a0lTsa+d DUbgh7t+lOXHdq4VYz0VlwX3lCFYFB9Lm27pp+hlnNM+4iymjU+rWrmDC8hvTSBH4Wv2 1CkyEz7xj5NMP4EM/vwkZawFtnVeCrcaL9+ByUY9j70Rdaig1pbM0LyMSpkkbYp1A5lL /mXaVwXO48K5isxqZhn8/7TsMvkeR+0Z9j4PvHF3GxA75g9scTENPeaggakn1ZRNx/nR 0GyKQl7X5aA60jsuye9ISomU28l0tO06+F4UFDCPU2V4zz1wWjvJKdL91tRtAT+Rq/2l vsRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=r1+fehePF1LQa+ETT3QS1bc9x/S6CdwPnRCT51uHUm4=; b=RnS9gh3MErJByLUg/0TbPiNDo3IzCLqHEyhLn+ZBhynIRKAJSJeVCdmhDvLnCFfj21 SlbnMS6GFYlaYeCogA/ogeX3zBWX7hAfXkS3dDG1eVBjcTGGy420YN1I4Pm07gYaaObx gs5azVrIGwOylPkHxvUe58CwO8jeeMlT9L8QjRk6gj6LpSZHexbSIkVkOf6qa/moxJ+D Tq4FbQCI2DQauwRSen/TzHT+F/ZDRxcteZKsr3ngPtMO7v8JSkyn6MpGr4pKaQ1RX2N7 kBdi4KPTqKh2bmu1dynRUFTuzsv4L/KJj22JwpwInMQ192hHr2tXn/RPYNnUVYNHIA7u bsGg== X-Gm-Message-State: AOAM531jlkkKzlbp78RoBT9vxnKm2RKnv+JYBy435Sz/587koiwMvy0V m5qbrV8Y8yGFImweohSPKSeLduL6d4ag80ILT1yEsA== X-Received: by 2002:a05:6512:2037:: with SMTP id s23mr13515499lfs.358.1619465053738; Mon, 26 Apr 2021 12:24:13 -0700 (PDT) MIME-Version: 1.0 References: <20210420192907.30880-1-longman@redhat.com> <20210420192907.30880-4-longman@redhat.com> In-Reply-To: <20210420192907.30880-4-longman@redhat.com> From: Shakeel Butt Date: Mon, 26 Apr 2021 12:24:02 -0700 Message-ID: Subject: Re: [PATCH-next v5 3/4] mm/memcg: Improve refill_obj_stock() performance To: Waiman Long Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , LKML , Cgroups , Linux MM , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Wei Yang , Masayoshi Mizuma , Xing Zhengjun , Matthew Wilcox Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 20, 2021 at 12:30 PM Waiman Long wrote: > > There are two issues with the current refill_obj_stock() code. First of > all, when nr_bytes reaches over PAGE_SIZE, it calls drain_obj_stock() to > atomically flush out remaining bytes to obj_cgroup, clear cached_objcg > and do a obj_cgroup_put(). It is likely that the same obj_cgroup will > be used again which leads to another call to drain_obj_stock() and > obj_cgroup_get() as well as atomically retrieve the available byte from > obj_cgroup. That is costly. Instead, we should just uncharge the excess > pages, reduce the stock bytes and be done with it. The drain_obj_stock() > function should only be called when obj_cgroup changes. > > Secondly, when charging an object of size not less than a page in > obj_cgroup_charge(), it is possible that the remaining bytes to be > refilled to the stock will overflow a page and cause refill_obj_stock() > to uncharge 1 page. To avoid the additional uncharge in this case, > a new overfill flag is added to refill_obj_stock() which will be set > when called from obj_cgroup_charge(). > > A multithreaded kmalloc+kfree microbenchmark on a 2-socket 48-core > 96-thread x86-64 system with 96 testing threads were run. Before this > patch, the total number of kilo kmalloc+kfree operations done for a 4k > large object by all the testing threads per second were 4,304 kops/s > (cgroup v1) and 8,478 kops/s (cgroup v2). After applying this patch, the > number were 4,731 (cgroup v1) and 418,142 (cgroup v2) respectively. This > represents a performance improvement of 1.10X (cgroup v1) and 49.3X > (cgroup v2). > > Signed-off-by: Waiman Long After incorporating Roman's suggestion, you can add: Reviewed-by: Shakeel Butt