Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp907872ybj; Sat, 21 Sep 2019 14:51:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8dCzIGV5nduuj2ntY/UJQ+6jDCADAH1+ycGbN1c/PYyuOCUWnu7873Ak54Qaps5AXOCaF X-Received: by 2002:a17:906:5295:: with SMTP id c21mr1670157ejm.80.1569102673162; Sat, 21 Sep 2019 14:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569102673; cv=none; d=google.com; s=arc-20160816; b=a5bxMttiahp7qgikswj1ZhqLaWjSAgAs63GxyEx6GHA1oxMdsESFYzaohqkJNyfNqZ 0Rr9YOjcL+J6IOY7AIDbgitYDThuqtWUavCBMuKtAiItLFUFIBBZQRp3Oofs3mG1yt0x 0MrOZy0azlA/zJK1AtrfMU8DpVsOKp+ae65R1DppR72GQ9CgV4S5aeiPqoYf+ng+rHgz 7+2HHbXgbisxfSObdQ2y9gOi8wbMywr3Wp5ixNzoPMdv9dTtcXj3RoglEHwiXgcBJyro +XLyuv/2xp8gQ7h3qosLwZAyTJ3kt0qniQul5Q10wYwNs29l/MoYwyjx22UrJ7y4VZrp xcDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=d8zb07k5dzkeSqLTrTbm5VEaA+uerVTLrmpHD00RHWo=; b=knQpjIUwfR/iAptMhv3nu55m9WCh1UZS2OUdA9lGvyi7DeyMyQ3yl9HcwcZvd8c6L/ lH/yQcQNf2oUqgfSaBa56NxwVyElfc7EzRlZlcgpw+Zpe+hXZmcFMjS6jU5vUbRo6Suw zzMGgcmSdWNSyfEvGoHFQVZlFYjKvPIPhQ+x/syHt49cUcduz8sFzBlAceaTrbfsCZUJ SeEhPNZrWwaihUDk0tor2JznVvKZjqh9MRKhGuaDkQwR92WjXh18QUPsWz/lJQ/NDkH3 GY67sjpcnMAcWCGTY1NqruXlVwZdRWy1x0qEYbZGg9uAnhHfkovFXmtkmzhrgCK272cD K1xQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si4012550edm.103.2019.09.21.14.50.49; Sat, 21 Sep 2019 14:51:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387803AbfITOUb (ORCPT + 99 others); Fri, 20 Sep 2019 10:20:31 -0400 Received: from relay.sw.ru ([185.231.240.75]:59714 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728861AbfITOUa (ORCPT ); Fri, 20 Sep 2019 10:20:30 -0400 Received: from [172.16.24.104] by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iBJlo-0006am-HJ; Fri, 20 Sep 2019 17:20:24 +0300 Subject: Re: [PATCH] mm, memcg: assign shrinker_map before kvfree To: "Kirill A. Shutemov" , Cyrill Gorcunov Cc: LKML , Linux MM , Johannes Weiner , Michal Hocko , Vladimir Davydov References: <20190920122907.GG2507@uranus.lan> <20190920132114.ofzphp53vqqjb3fs@box> From: Kirill Tkhai Message-ID: <55c22ce3-5e42-f7a1-3861-8e0cb73d26de@virtuozzo.com> Date: Fri, 20 Sep 2019 17:20:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20190920132114.ofzphp53vqqjb3fs@box> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20.09.2019 16:21, Kirill A. Shutemov wrote: > On Fri, Sep 20, 2019 at 03:29:07PM +0300, Cyrill Gorcunov wrote: >> Currently there is a small gap between fetching pointer, calling >> kvfree and assign its value to nil. In current callgraph it is >> not a problem (since memcg_free_shrinker_maps is running from >> memcg_alloc_shrinker_maps and mem_cgroup_css_free only) still >> this looks suspicious and we can easily eliminate the gap at all. > > With this logic it will still look suspicious since you don't wait a grace > period before freeing the map. This freeing occurs in the moment, when nobody can dereference shrinker_map in parallel: memcg is either not yet online or its css->refcnt is already dead. This NULLifying is needed just to prevent double freeing of shrinker_map. Please, see the explanation in my email to our namesake. Kirill