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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DBC1C433F5 for ; Mon, 1 Nov 2021 09:20:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9178611C1 for ; Mon, 1 Nov 2021 09:20:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D9178611C1 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3157F94000C; Mon, 1 Nov 2021 05:20:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C5B3940008; Mon, 1 Nov 2021 05:20:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B49494000C; Mon, 1 Nov 2021 05:20:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 0E305940008 for ; Mon, 1 Nov 2021 05:20:33 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BC20D1822D2A8 for ; Mon, 1 Nov 2021 09:20:32 +0000 (UTC) X-FDA: 78759815946.01.98B3B56 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf18.hostedemail.com (Postfix) with ESMTP id 44460400208E for ; Mon, 1 Nov 2021 09:20:32 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 2A9111FD6C; Mon, 1 Nov 2021 09:20:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1635758431; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QxZsaHY6gyKicFl7Ca0r84GnJJI+weQVCmj9Rc1Aj7c=; b=iQdT1rOBvrCD35oxrrXxFw6ODbaFi6TIyiVTY0/6qnQXIF6RAza/Re/qYhYCBGz4XoHDxg G3fdLMDljcWl/rAlpJC05Ms/VJCE+oQucKCO4WwFEpf3nsHl/44WKvq6ou0YzIUiQmsYoS UInE1Gs/pB6KdGNh49BgTtPDs5xT19Q= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C1875A3B88; Mon, 1 Nov 2021 09:20:30 +0000 (UTC) Date: Mon, 1 Nov 2021 10:20:27 +0100 From: Michal Hocko To: ning zhang Cc: linux-mm@kvack.org, Andrew Morton , Johannes Weiner , Vladimir Davydov , Yu Zhao Subject: Re: [RFC 0/6] Reclaim zero subpages of thp to avoid memory bloat Message-ID: References: <1635422215-99394-1-git-send-email-ningzhang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 44460400208E X-Stat-Signature: qedq8z833zsk6zo6jjm66e3ti36inpsh Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=iQdT1rOB; spf=pass (imf18.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-HE-Tag: 1635758432-759359 Content-Transfer-Encoding: quoted-printable 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 Sat 30-10-21 00:12:53, ning zhang wrote: >=20 > =E5=9C=A8 2021/10/29 =E4=B8=8B=E5=8D=889:38, Michal Hocko =E5=86=99=E9=81= =93: > > On Thu 28-10-21 19:56:49, Ning Zhang wrote: > > > As we know, thp may lead to memory bloat which may cause OOM. > > > Through testing with some apps, we found that the reason of > > > memory bloat is a huge page may contain some zero subpages > > > (may accessed or not). And we found that most zero subpages > > > are centralized in a few huge pages. > > >=20 > > > Following is a text_classification_rnn case for tensorflow: > > >=20 > > > zero_subpages huge_pages waste > > > [ 0, 1) 186 0.00% > > > [ 1, 2) 23 0.01% > > > [ 2, 4) 36 0.02% > > > [ 4, 8) 67 0.08% > > > [ 8, 16) 80 0.23% > > > [ 16, 32) 109 0.61% > > > [ 32, 64) 44 0.49% > > > [ 64, 128) 12 0.30% > > > [ 128, 256) 28 1.54% > > > [ 256, 513) 159 18.03% > > >=20 > > > In the case, there are 187 huge pages (25% of the total huge pages) > > > which contain more then 128 zero subpages. And these huge pages > > > lead to 19.57% waste of the total rss. It means we can reclaim > > > 19.57% memory by splitting the 187 huge pages and reclaiming the > > > zero subpages. > > What is the THP policy configuration in your testing? I assume you ar= e > > using defaults right? That would be always for THP and madvise for > > defrag. Would it make more sense to use madvise mode for THP for your > > workload? The THP code is rather complex and just by looking at the > > diffstat this add quite a lot on top. Is this really worth it? >=20 > The THP configuration is always. >=20 > Madvise needs users to set MADV_HUGEPAGE by themselves if they want use= huge > page, while many users don't do set this, and they can't control this w= ell. What do you mean tey can't control this well?=20 > Such as java, users can set heap and metaspace to use huge pages with > madvise, but there is also memory bloat. Users still need to test wheth= er > their app can accept the waste. There will always be some internal fragmentation when huge pages are used. The amount will depend on how well the memory is used but huge pages give a performance boost in return. If the memory bloat is a significant problem then overeager THP usage is certainly not good and I would argue that applying THP always policy is not a proper configuration. No matter how much the MM code can try to fix up the situation it will be always a catch up game. =20 > For the case above, if we set THP configuration to be madvise, all the = pages > it uses will be 4K-page. >=20 > Memory bloat is one of the most important reasons that users disable TH= P.=C2=A0 > We do this to popularize THP to be default enabled. To my knowledge the most popular reason to disable THP is the runtime overhead. A large part of that overhead has been reduced by not doing heavy compaction during the page fault allocations by default. Memory overhead is certainly an important aspect as well but there is always a possibility to reduce that by reducing it to madvised regions for page fault (i.e. those where author of the code has considered the costs vs. benefits of the huge page) and setting up a conservative khugepaged policy. So there are existing tools available. You are trying to add quite a lot of code so you should have good arguments to add more complexity. I am not sure that popularizing THP is a strong one TBH. --=20 Michal Hocko SUSE Labs