Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36682304rwd; Tue, 11 Jul 2023 04:29:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlG3pwr9yugNk7XrF0r0mdgsWZkhmWY/vSekYw+DBWGZYopJRjo+da3qhuSPAEw9J38boTzo X-Received: by 2002:a17:902:ab01:b0:1b8:5a32:2345 with SMTP id ik1-20020a170902ab0100b001b85a322345mr10197409plb.22.1689074945713; Tue, 11 Jul 2023 04:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689074945; cv=none; d=google.com; s=arc-20160816; b=E/THcENd0CDb9Fb/mGpTurDA37ZdfgMEupPdgap+SimPx961GThOwtS159+8w/AS0r QZzYF3CMrBs+JbDowqg8ck6Z2RvgbC6eHl1Xrkj7Vs1Fg0sFTiCcRS4Jfm8cg8AkjTS9 SAuhwK5gU+8Ww1Idp7QVu9eoK9ts2CuiLgg/ZIFPMuaQEeJy2UdOZLX0swuhF2VSctPk gBazGQ7kTgU0M8k/DGU/sp+ugBhfI8LN8gfZn3+HQLtoCQ/3fiYCroK0noXxh1bvSm1w UULl9sufTcHeRWeC9mZEr2aNw3PJzm0s6XwrplpmUD/UrMG5Ov94iAzA3FU57zFYw0Uj TNEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vGMYxsXzKbG1bvPGCq5W+EjH0inuuCTmPCtfSounG5c=; fh=Sg2bUVYUsD+HF3IIUIe+Gx6mhI+KYeqAdFvCBtfVhYE=; b=UtI49x9vl49dztYcCvTF6e0biLZOux6X0xSY9BbyQpZHaI5j/7QqDeWBtPtfUgano5 wXzh1xsLLayydMwvIpt7ATNlixPLoinvItW6F+grthVxHL/ps+YGzmoCBQdz4hzAwsmp es73WkXe21pd/9jyhvr8ANBqx1o6/FpirDEAS2y92CYNI6FubaP64QrXEJgVt479lUgF lWIqTkrtLMlsOt9lcDE2Lq49Sk5eQTKId2DxzNwYTQgJOxMzP7SPf+/8EGfjcgGz8iky iL2FuyBd/NUKR5Zs8jPJScIyclWgHBAFlDlWyHf3GIZ+M5lwTp9JaKNZk8/SslJBmurN ugrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ifBDuDly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w21-20020a170902d71500b001b9e0d0a01fsi1415823ply.256.2023.07.11.04.28.53; Tue, 11 Jul 2023 04:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ifBDuDly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbjGKLTv (ORCPT + 99 others); Tue, 11 Jul 2023 07:19:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjGKLTt (ORCPT ); Tue, 11 Jul 2023 07:19:49 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B7F911D for ; Tue, 11 Jul 2023 04:19:48 -0700 (PDT) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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