Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A08DFEB64DC for ; Tue, 11 Jul 2023 11:19:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DADC16B0071; Tue, 11 Jul 2023 07:19:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5E0E6B0074; Tue, 11 Jul 2023 07:19:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C25876B0075; Tue, 11 Jul 2023 07:19:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B2FCE6B0071 for ; Tue, 11 Jul 2023 07:19:50 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 79F47120172 for ; Tue, 11 Jul 2023 11:19:50 +0000 (UTC) X-FDA: 80999086140.04.0D02987 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf07.hostedemail.com (Postfix) with ESMTP id 96DC44000A for ; Tue, 11 Jul 2023 11:19:48 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ifBDuDly; dmarc=pass (policy=quarantine) header.from=suse.com; spf=none (imf07.hostedemail.com: domain of mhocko@suse.com has no SPF policy when checking 195.135.220.29) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689074388; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vGMYxsXzKbG1bvPGCq5W+EjH0inuuCTmPCtfSounG5c=; b=zuUbrRLR+qOGknSt4AX652SGAHA6xExZpMc5thEKQEj/KEsqbGD4JFvugBnGQr81Dg+/R3 fPgPGVBKquXwFu/QFBJXQTSziJVo2q8ytCPp7xbXJTsJlQ9ldT+w+YRo4IWZtcqc8cVyRr jn5ILLLofjjOa/BkCrKKYgCC0sUc+fE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ifBDuDly; dmarc=pass (policy=quarantine) header.from=suse.com; spf=none (imf07.hostedemail.com: domain of mhocko@suse.com has no SPF policy when checking 195.135.220.29) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689074388; a=rsa-sha256; cv=none; b=brc5hICxcE5+y3XKRZoQNvoeaZ7hLuQdpA26veXJ3sbZNmCr7i7gOdbRtTUO1n5Z1X8jRu JZw9gpzbRI1RRKomPQMNyKtNl2sCWPxBwpbuaXdj//eWuuujMpcoHstCzpZ90hArHt68BM 2KgtTew1y0KiiirHzrqva5k/gj3rfng= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1160D1FE81; Tue, 11 Jul 2023 11:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1689074387; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vGMYxsXzKbG1bvPGCq5W+EjH0inuuCTmPCtfSounG5c=; b=ifBDuDlyABFVdELO5yxYSfjgZ01Dcbl6cnUClS7O0OEnWo0wZdgqkmnkVUpqfs/ec4Pflt nMS8J3nsSPANHIwe9Q1Uguv2zCRiibkYhW17TzXVtJLuHusfprOztkIrnemvP5ER4igTUE CVyLaQpqAHsFLdgrrfAdqLYdqRY2JwA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E2A471390F; Tue, 11 Jul 2023 11:19:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cghzNNI6rWRGGAAAMHmgww (envelope-from ); Tue, 11 Jul 2023 11:19:46 +0000 Date: Tue, 11 Jul 2023 13:19:46 +0200 From: Michal Hocko To: Huang Ying Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Arjan Van De Ven , Andrew Morton , Mel Gorman , Vlastimil Babka , David Hildenbrand , Johannes Weiner , Dave Hansen , Pavel Tatashin , Matthew Wilcox Subject: Re: [RFC 2/2] mm: alloc/free depth based PCP high auto-tuning Message-ID: References: <20230710065325.290366-1-ying.huang@intel.com> <20230710065325.290366-3-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230710065325.290366-3-ying.huang@intel.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 96DC44000A X-Stat-Signature: ch7qerdqsi9zrrbh8iou9k1kkeeytwex X-Rspam-User: X-HE-Tag: 1689074388-380218 X-HE-Meta: U2FsdGVkX1/DqnRWKXbAAbcl35hzE/zCUnJGzaW2tR1dvcslhdWy+jcgh6FkYm3hBFT1rdrnAYkA5s64ISZttHrAwVgM+KBBKpD7y2vk+ezfJWakemXXDmYiQKwAZpS1TWbEUDWU8b5JiqcLbyDQfBowmSSmkLJ4vSwc35dy1lMWOi/4OdxfOT3mEzf3YNizicsaBxUgJ4Pn3ie01cM2LFbwGJeFHjda5vzW0mDF7e4e7jtwcxqmGJkzr7mLjRnwTBv5CSy66L4hOLSbYrxgCvP7modJZOgFhdBpJiKb6+QpJ5jTg88Tk4nRG0RTfBl5Uz2tvAs0JEH3D2FRovBbaTMkN9bp8D01SXv3ykc0fzPp1S4Byw2MliVF0hDGi7G98kpqlLB9sydKvbE1/0IPd0gSeP8VPH1BOR5QhriVESWJxcG8gIAC0rDMfUw9kjZjAoRmqBkLVmQJ5067Sa+NREMpIUlOZrZEyAlOjenkQcjr7XJiyzu/Tb5dauJmgh/PnP6kA5CPpyUyuFC4Z7DkZuod6Ha2haDYEGSMzc9Nn8Q7C5M4Ud960uG0ldSs1Dtasx0Q4hKjt87nDL39w8fjy+omKrmHwfKP6pHstVs/k7B3Wxt/3peTZZGuzoMbyuoOgni96fNwXGD5mZxiAmhnAQGo4I9oL6yBaV3u2GJv61EfbVoLnhJZM2qPJS/VxwRkjQKP6JczIFW6GBKLbYj1URoqHnpk9YSdiHAQ/vp7FTBKMdBPZg+32GwUyKGtELETMvJhBFs0GaNks+Src5XQfXHgEDaZ/R7GQcGL6cAZslVuU4zddZ98qrbS5AJVm8+TioKhr95riRETGC0PaDccE1IBGkxA7SZu9+hnojaCCnoK10WQEZ9IVVnjQ/htS//kzL+q1DCOXlt9aLde46PA/9QZDdWHftKC5grlHWm3eb5iSbQkRdsf/+Ab+HSn2DE9KAGwpr4lUwUxo8jV7BK lBvU4865 +Mez4poo0EuH0KqeJg80++rPWp5yxOq+JI+WfS5kOJ7bHxCRe1M7s05kHqS7IRLPAikTDsb9zRjxqYxbSaHdZvkdyjyMhTfX0/fXk/t58KDN6FnLIS/MHwu6YO1zIBR8xLsPs47wrebjfnis= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon 10-07-23 14:53:25, Huang Ying wrote: > To auto-tune PCP high for each CPU automatically, an > allocation/freeing depth based PCP high auto-tuning algorithm is > implemented in this patch. > > The basic idea behind the algorithm is to detect the repetitive > allocation and freeing pattern with short enough period (about 1 > second). The period needs to be short to respond to allocation and > freeing pattern changes quickly and control the memory wasted by > unnecessary caching. 1s is an ethernity from the allocation POV. Is a time based sampling really a good choice? I would have expected a natural allocation/freeing feedback mechanism. I.e. double the batch size when the batch is consumed and it requires to be refilled and shrink it under memory pressure (GFP_NOWAIT allocation fails) or when the surplus grows too high over batch (e.g. twice as much). Have you considered something as simple as that? Quite honestly I am not sure time based approach is a good choice because memory consumptions tends to be quite bulky (e.g. application starts or workload transitions based on requests). > To detect the repetitive allocation and freeing pattern, the > alloc/free depth is calculated for each tuning period (1 second) on > each CPU. To calculate the alloc/free depth, we track the alloc > count. Which increases for page allocation from PCP and decreases for > page freeing to PCP. The alloc depth is the maximum alloc count > difference between the later large value and former small value. > While, the free depth is the maximum alloc count difference between > the former large value and the later small value. > > Then, the average alloc/free depth in multiple tuning periods is > calculated, with the old alloc/free depth decay in the average > gradually. > > Finally, the PCP high is set to be the smaller value of average alloc > depth and average free depth, after clamped between the default and > the max PCP high. In this way, pure allocation or freeing will not > enlarge the PCP high because PCP doesn't help. > > We have tested the algorithm with several workloads on Intel's > 2-socket server machines. How does this scheme deal with memory pressure? -- Michal Hocko SUSE Labs