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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EA2CC433E1 for ; Wed, 27 May 2020 19:56:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC31820835 for ; Wed, 27 May 2020 19:56:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="F0kLEdkP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC31820835 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6CBC48001A; Wed, 27 May 2020 15:56:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67B0A80010; Wed, 27 May 2020 15:56:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58FB58001A; Wed, 27 May 2020 15:56:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 42AC780010 for ; Wed, 27 May 2020 15:56:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EE667DB1F6 for ; Wed, 27 May 2020 19:56:41 +0000 (UTC) X-FDA: 76863556602.05.nest92_3a63c8d090a1a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id D148F1801FA5B for ; Wed, 27 May 2020 19:56:41 +0000 (UTC) X-HE-Tag: nest92_3a63c8d090a1a X-Filterd-Recvd-Size: 5099 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 May 2020 19:56:41 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id b27so823200qka.4 for ; Wed, 27 May 2020 12:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uWtuI3UUqrcr2MPYY5t1qIqp8t2VdGpdGQyBHayc2+I=; b=F0kLEdkPRpFO9sH4wIpK6WFmkk+axi+AF8AIp2TUrvRiQ5IBMPR/xY35x5yDhSQmEe 7qd3x3C70smXp6N9YZ2ugYa3/Edu51g8JTb+5dcxs5oHL7ox91AXyxIRsBkNIrYvMNeH /dBAvk1ujz0GqKOEewegiRaGmAm25tBIInVhUFdlxeO4s44vafo89W6zlYBv5HJtjsas a2o4WMkqr9p6Reb7lyX2opm9Ze5J09sHAUyJ5Gz8293k4J/CSalOGy6VrI+87azCztME 6DuFJ5GyV9LZVq40cWVEKHdf5ipbGToeGK5YW1ffw/2l1Yi6PK6sx8fY0OZYSosgdSIo d/4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uWtuI3UUqrcr2MPYY5t1qIqp8t2VdGpdGQyBHayc2+I=; b=T205LMYEQ1ftkFpT25WpZaCqiqGTrBXrK6C7ZbjvYqFiJxwiti3HQQcxoM9m/1RXE3 9Nf4PX2zqn549KOSQhw6XI3+af/DeTMJDggBaUJdc/u9rsKuOnA1p0BwcSkFU80g53ds U2puVymYmbMjXaz8FgWDB2RcsGRAIPbHuFBVcFMWos9pgf/lToJJ3THlV/ky1d5cLO9A KWkugu4P+NB4ejvC/m2wcC1p4FXwtb/A9Y3CqYSnWJbIxAPbtxfjo+8x0L7kFCbjuI39 YkXzLsNbp1dJSKUKDb+/YC+UWDEJ5vBYA9wCd+psobo2flnLBTqlxRP0MPtTxPgnwnoD GPRA== X-Gm-Message-State: AOAM532XgB2KeYXFe3rqIRcKdFSJR2d+PYTGZldQnBbeZZK8uYBpZXNj Z/bGrhHABheR7YfqyNjV5yCYKg== X-Google-Smtp-Source: ABdhPJzlAziYYOCm4VXEycz3sNv4Do6UvsXICCUPA0HIuaPoefFQjqsdZvAOOeXzo/yJ5MNL3mZ2OA== X-Received: by 2002:a37:79c5:: with SMTP id u188mr5718286qkc.300.1590609400422; Wed, 27 May 2020 12:56:40 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:2535]) by smtp.gmail.com with ESMTPSA id s74sm3135071qka.54.2020.05.27.12.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 12:56:39 -0700 (PDT) Date: Wed, 27 May 2020 15:56:14 -0400 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , Christoph Lameter , Michal Hocko , Shakeel Butt , linux-mm@kvack.org, Vlastimil Babka , kernel-team@fb.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 06/19] mm: memcg/slab: obj_cgroup API Message-ID: <20200527195614.GC47905@cmpxchg.org> References: <20200526214227.989341-1-guro@fb.com> <20200526214227.989341-7-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200526214227.989341-7-guro@fb.com> X-Rspamd-Queue-Id: D148F1801FA5B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 Tue, May 26, 2020 at 02:42:14PM -0700, Roman Gushchin wrote: > @@ -257,6 +257,98 @@ struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr) > } > > #ifdef CONFIG_MEMCG_KMEM > +extern spinlock_t css_set_lock; > + > +static void obj_cgroup_release(struct percpu_ref *ref) > +{ > + struct obj_cgroup *objcg = container_of(ref, struct obj_cgroup, refcnt); > + struct mem_cgroup *memcg; > + unsigned int nr_bytes; > + unsigned int nr_pages; > + unsigned long flags; > + > + /* > + * At this point all allocated objects are freed, and > + * objcg->nr_charged_bytes can't have an arbitrary byte value. > + * However, it can be PAGE_SIZE or (x * PAGE_SIZE). > + * > + * The following sequence can lead to it: > + * 1) CPU0: objcg == stock->cached_objcg > + * 2) CPU1: we do a small allocation (e.g. 92 bytes), > + * PAGE_SIZE bytes are charged > + * 3) CPU1: a process from another memcg is allocating something, > + * the stock if flushed, > + * objcg->nr_charged_bytes = PAGE_SIZE - 92 > + * 5) CPU0: we do release this object, > + * 92 bytes are added to stock->nr_bytes > + * 6) CPU0: stock is flushed, > + * 92 bytes are added to objcg->nr_charged_bytes > + * > + * In the result, nr_charged_bytes == PAGE_SIZE. > + * This page will be uncharged in obj_cgroup_release(). > + */ Thanks for adding this. > +int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size) > +{ > + struct mem_cgroup *memcg; > + unsigned int nr_pages, nr_bytes; > + int ret; > + > + if (consume_obj_stock(objcg, size)) > + return 0; > + > + rcu_read_lock(); > + memcg = obj_cgroup_memcg(objcg); > + css_get(&memcg->css); > + rcu_read_unlock(); Can you please also add the comment here I mentioned last time? To explain why we're not checking objcg->nr_charged_bytes if we have already pre-allocated bytes that could satisfy the allocation. Otherwise, looks good to me.