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 4062AC433FE for ; Thu, 7 Oct 2021 14:00:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96EE260FD7 for ; Thu, 7 Oct 2021 14:00:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 96EE260FD7 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 C82B0900002; Thu, 7 Oct 2021 10:00:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C31086B0072; Thu, 7 Oct 2021 10:00:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAA23900002; Thu, 7 Oct 2021 10:00:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 990276B0071 for ; Thu, 7 Oct 2021 10:00:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4D50627716 for ; Thu, 7 Oct 2021 14:00:25 +0000 (UTC) X-FDA: 78669801210.13.550D7CE Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf10.hostedemail.com (Postfix) with ESMTP id D39CF6006A22 for ; Thu, 7 Oct 2021 14:00:23 +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-out2.suse.de (Postfix) with ESMTPS id 591D3200BE; Thu, 7 Oct 2021 14:00:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1633615222; 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=jGhSWzI+PuqGNcE+T8UMjVNVsLgxFGP2hreevAIqd60=; b=S1aB24FYThKU4At27vhzZmHUc46bEaLhYREZ9O1eI+nEAW61YPhSJYgtcGGZrYwdpNfzDq NT4uaUzJrqA7DWyJDBLjsbkMccDwFte58GQvGfxesqQMGNjyH/Roww01s2ei0kCw3EeM5R 2UiYyRVtLkFrTiZW8WeXpyU6Gh7+7xs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1633615222; 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=jGhSWzI+PuqGNcE+T8UMjVNVsLgxFGP2hreevAIqd60=; b=EOQXBkC0oMqI/99qT0eRzoEijjqG87XUpxSptWKxj4c1VnP6mvX7wctQQrVKhjg2MQwcXc D65FSGkHW5hfLaCw== 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 2E2A013EAC; Thu, 7 Oct 2021 14:00:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id LnN0Cnb9XmFeSQAAMHmgww (envelope-from ); Thu, 07 Oct 2021 14:00:22 +0000 Message-ID: <0668b6d8-6f8c-07c7-75e0-5448ea87cb54@suse.cz> Date: Thu, 7 Oct 2021 16:00:21 +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: Vasily Averin , Michal Hocko Cc: 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> From: Vlastimil Babka In-Reply-To: <953ef8e2-1221-a12c-8f71-e34e477a52e8@virtuozzo.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=S1aB24FY; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=EOQXBkC0; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D39CF6006A22 X-Stat-Signature: xtowjtd4pug376mxcge3t6t8jw644fbt X-HE-Tag: 1633615223-134409 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 10:50, 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. > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index b37435c274cf..e6abe2cac159 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5290,6 +5290,12 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, > > page = __rmqueue_pcplist(zone, 0, ac.migratetype, alloc_flags, > pcp, pcp_list); > + > + if (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT) && page && > + unlikely(__memcg_kmem_charge_page(page, gfp, 0) != 0)) { > + __free_pages(page, 0); It's too early for this here, we didn't go through prep_new_page() yet, minimally the post_alloc_hook() -> set_page_refcounted() part, required for put_page_testzero() in __free_pages() to work properly, and probably other stuff. Either do the full prep+free or a minimal reversion of __rmqueue_pcplist - something to just put the page back to pcplist. Probably the former so we don't introduce subtle errors. > + page = NULL; > + } > if (unlikely(!page)) { > /* Try and get at least one page */ > if (!nr_populated) >