From mboxrd@z Thu Jan 1 00:00:00 1970 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 C08BAC433EF for ; Thu, 7 Oct 2021 14:02:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D1AD61075 for ; Thu, 7 Oct 2021 14:02:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4D1AD61075 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A344D6B0071; Thu, 7 Oct 2021 10:02:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E4ED900003; Thu, 7 Oct 2021 10:02:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AC21900002; Thu, 7 Oct 2021 10:02:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 7E0C16B0071 for ; Thu, 7 Oct 2021 10:02:51 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1FF351841FC7B for ; Thu, 7 Oct 2021 14:02:51 +0000 (UTC) X-FDA: 78669807342.35.E5DA1F9 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf04.hostedemail.com (Postfix) with ESMTP id 991445001996 for ; Thu, 7 Oct 2021 14:02:50 +0000 (UTC) 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-out1.suse.de (Postfix) with ESMTPS id 9AB2A2252E; Thu, 7 Oct 2021 14:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1633615369; 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=1I72EYHnG0Ll/HtrsN+KFVKnf7WVgvBWjvAI6syAjqc=; b=0uOaaQ3swvj/d6JA0JLHXjhrMnICVVihcAMhbNoESIBzDXF7wGhBdCOiw2egny1Mj9RA1t d5Igur3Ir+M8wsPuOoU7YQ/HWPev32nCQhlHzHuUyo2qBfYTss6q8Qt9+WWXhFn4dakcLn CSli04vid3caxE0XpC0Dug0onC0vq5g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1633615369; 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=1I72EYHnG0Ll/HtrsN+KFVKnf7WVgvBWjvAI6syAjqc=; b=Oircnie37Y2Jpq7n+YZeuPH8FCaUWZ0KaH3snZf+FZ6algRf7L9cQlHyTUzi9iCx1AIydy kD9P/UVCr4ES+JDQ== 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 6880813EAC; Thu, 7 Oct 2021 14:02:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id asXEGAn+XmFXSwAAMHmgww (envelope-from ); Thu, 07 Oct 2021 14:02:49 +0000 Message-ID: Date: Thu, 7 Oct 2021 16:02:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: memcg memory accounting in vmalloc is broken Content-Language: en-US To: Mel Gorman , Vasily Averin Cc: Michal Hocko , Johannes Weiner , Vladimir Davydov , Andrew Morton , Cgroups , Linux MM , "linux-kernel@vger.kernel.org" , kernel@openvz.org, Mel Gorman , Uladzislau Rezki References: <953ef8e2-1221-a12c-8f71-e34e477a52e8@virtuozzo.com> <20211007102044.GR3959@techsingularity.net> From: Vlastimil Babka In-Reply-To: <20211007102044.GR3959@techsingularity.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 991445001996 X-Stat-Signature: 969og9on1wr9eenb9cujoq4ddsehi6x7 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=0uOaaQ3s; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Oircnie3; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-HE-Tag: 1633615370-980196 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 10/7/21 12:20, Mel Gorman wrote: > On Thu, Oct 07, 2021 at 11:50:44AM +0300, Vasily Averin wrote: >> On 10/7/21 11:16 AM, Michal Hocko wrote: >> > Cc Mel and Uladzislau >> > >> > On Thu 07-10-21 10:13:23, Michal Hocko wrote: >> >> On Thu 07-10-21 11:04:40, Vasily Averin wrote: >> >>> vmalloc was switched to __alloc_pages_bulk but it does not account the memory to memcg. >> >>> >> >>> Is it known issue perhaps? >> >> >> >> No, I think this was just overlooked. Definitely doesn't look >> >> intentional to me. >> >> I use following patch as a quick fix, >> it helps though it is far from ideal and can be optimized. > > Thanks Vasily. > > This papers over the problem but it could certainly be optimized. At > minimum; > > 1. Test (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT)) in the > function preamble and store the result in a bool memcg_kmem_enabled() is a static key based check so caching that defeats its purpose and changes it to a normal branch. That leaves gfp & __GFP_ACCOUNT, which may perhaps still benefit from such caching. > 2. Avoid the temptation to batch the accounting because if the > accounting fails, there is no information on how many pages could be > allocated before the limits were hit. I guess you could pre-charge the > pages and uncharging the number of pages that failed to be allocated > but it should be a separate patch. > 3. If an allocation fails due to memcg accounting, break > out of the loop because all remaining bulk allocations are > also likely to fail. > > As it's not vmalloc's fault, I would suggest the patch > have > Fixes: 387ba26fb1cb ("mm/page_alloc: add a bulk page allocator") > and > Cc: > > Note the Cc should just be in the patch and not mailed directly to > stable@ as it'll simply trigger a form letter about the patch having to > be merged to mainline first. >