Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3660858ybi; Mon, 27 May 2019 03:56:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPzzE+teiHliYZNGg+2QiAGIpa4qh+tav/mShuLS57sN5FiQVbXOEyekqfKFBVmbquZsdg X-Received: by 2002:a17:902:1029:: with SMTP id b38mr86531790pla.72.1558954604820; Mon, 27 May 2019 03:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558954604; cv=none; d=google.com; s=arc-20160816; b=FbJ+8UJHrH8tdbwaAsihEOgGlwhEhuFjynRB1DhvbUFPRsVBERuIBYFzvJRmu9iFyq LFS/HZRZNzrCIGKB/I83FAG/EMrdO/xBD4uqhW3rvtcTQZTBdMhtElSLhEJrYAYSx/N1 PGKRxZxD3T7MwD2J1/BIXkYlVdaR84CokEN+rfKpdq6q7VK7zG6HhYpkAo4+MuyWqAzc JAeLHu7OjNgzaHxDRMlaqlI3ivw1NDE52kiCqA49qkV1OrZllcHNfjxZyc3aw87CvHym eANTmSezFRH54hln7C4tOKqYF73JOvO3S2sUG2hbXCcnBLyFXGW99o9vq5d9vyDIIEsl lAMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=T2n4gBNEt3oKhgRBGoBZWnyBBkiJxP3xEBbVU5SxBlY=; b=C6F0KabNg2Wmep4PJyA81HHNcXUXTTDRAxtVAHLkNYRPpdANbZvjNKisabfdGIODmk YWcv8cb6YNpHYEqO89Hh+Jp28F7t3NzinEbhUO95+SqR7E7auLfkwZrrGtGXGI1aSmB0 8koVXTTOq0NTmSRRpQT934mrbbjiQ37LpbFnF5x9g//N7gH/4p7/krCOKaq2hFq0hcX3 Xq2w+cLtU4fSFiJ9cKSQdHLkASddShMUvoj7IqY+IvbVGf1z+CpKN3Cncy9BSm1Cyclw xqp0Tx/ExlTaU0rDJ6c7gedHb5vggjMUxYi7Dxq+BJzzLTmjRzneLgFj4S7V3rf4Ujww HDvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dR84Z3nu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10si6974396pgo.0.2019.05.27.03.56.29; Mon, 27 May 2019 03:56:44 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dR84Z3nu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726545AbfE0Kyi (ORCPT + 99 others); Mon, 27 May 2019 06:54:38 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:42432 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbfE0Kyh (ORCPT ); Mon, 27 May 2019 06:54:37 -0400 Received: by mail-lf1-f65.google.com with SMTP id y13so11706354lfh.9 for ; Mon, 27 May 2019 03:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T2n4gBNEt3oKhgRBGoBZWnyBBkiJxP3xEBbVU5SxBlY=; b=dR84Z3nuv3s5YOrQqiLB6Ix9wMQyT82iqcq3wrUTRa/kZxr+uBwRmuVxh7hx4Lj3FM KEhFHkxTmGv6Kam6nBU+3HqKorCFNvjw9OKzYn2VNr6iYG7Vd9fuyzf40YRt32xz2mSg bOlKoojrSHXP5UsyZ7jQAqUTsUqLpKSgzi5DR4/VRyJe0G/djkI1+RjUawiyvAvHZEv3 3XP1nkgpkAxPkHG7+BRQVTg9/MdbHsZdjvMS8pi4eVrG7fJTgAEcOXKiSiV6YDPNq6jw 6xUNJqhwJr+anTyRiB+gdR3lBXp1Y/etJgAXzlqqmzfgEdAxjIYaFfuQhg6wQqVmQwf3 vXaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T2n4gBNEt3oKhgRBGoBZWnyBBkiJxP3xEBbVU5SxBlY=; b=gnAkhaXxUbFbmYFSXjLqTXc01TffCzh331d2HSTtVn6d21W7tZFUb9TEOZwHxQEuU3 RzQWaI4bCoIWWgkTK4xVfoqi0WlDjvGcrI667h/9pWaqNjzFJ0BaxUAN0Tmp/OPSyFMF 8ksEuDobjD+gTx2hof1K8gq9+GfKkvtyZjHk5QzOlbNIrfqInEAe5/HjnNIavAxW6Kdy iL62QDy7TRzp1o0KZwweO2qSVG7ywCy2mIzMt3P7/1+ZTgD/gGRk29icZFjr+/JN20bI IT/uqPZDWiMJO1bNzW5A6BG6Bgwp2D5lEPMvRGMn0QLqetb318rIaOh0L/dbIMf/WaTT 4RLQ== X-Gm-Message-State: APjAAAV/oNEeutnI7acJBWNIgziL8+1G97ngpDalg9bYpSh9SwZqCDRk WpslEPMdFcB+5i6PX3soEYcZzbsyBDb7kdZ0HEY= X-Received: by 2002:a19:9e46:: with SMTP id h67mr8374590lfe.120.1558954475111; Mon, 27 May 2019 03:54:35 -0700 (PDT) MIME-Version: 1.0 References: <20190524174918.71074b358001bdbf1c23cd77@gmail.com> <20190525150948.e1ff1a2a894ca8110abc8183@linux-foundation.org> In-Reply-To: <20190525150948.e1ff1a2a894ca8110abc8183@linux-foundation.org> From: Vitaly Wool Date: Mon, 27 May 2019 12:54:23 +0200 Message-ID: Subject: Re: [PATCH] z3fold: add inter-page compaction To: Andrew Morton Cc: Linux-MM , LKML , Dan Streetman , Oleksiy.Avramchenko@sony.com, Bartlomiej Zolnierkiewicz , Uladzislau Rezki Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 26, 2019 at 12:09 AM Andrew Morton wrote: > Forward-declaring inline functions is peculiar, but it does appear to work. > > z3fold is quite inline-happy. Fortunately the compiler will ignore the > inline hint if it seems a bad idea. Even then, the below shrinks > z3fold.o text from 30k to 27k. Which might even make it faster.... It is faster with inlines, I'll try to find a better balance between size and performance in the next version of the patch though. > > > > ... > > > > +static inline struct z3fold_header *__get_z3fold_header(unsigned long handle, > > + bool lock) > > +{ > > + struct z3fold_buddy_slots *slots; > > + struct z3fold_header *zhdr; > > + unsigned int seq; > > + bool is_valid; > > + > > + if (!(handle & (1 << PAGE_HEADLESS))) { > > + slots = handle_to_slots(handle); > > + do { > > + unsigned long addr; > > + > > + seq = read_seqbegin(&slots->seqlock); > > + addr = *(unsigned long *)handle; > > + zhdr = (struct z3fold_header *)(addr & PAGE_MASK); > > + preempt_disable(); > > Why is this done? > > > + is_valid = !read_seqretry(&slots->seqlock, seq); > > + if (!is_valid) { > > + preempt_enable(); > > + continue; > > + } > > + /* > > + * if we are here, zhdr is a pointer to a valid z3fold > > + * header. Lock it! And then re-check if someone has > > + * changed which z3fold page this handle points to > > + */ > > + if (lock) > > + z3fold_page_lock(zhdr); > > + preempt_enable(); > > + /* > > + * we use is_valid as a "cached" value: if it's false, > > + * no other checks needed, have to go one more round > > + */ > > + } while (!is_valid || (read_seqretry(&slots->seqlock, seq) && > > + (lock ? ({ z3fold_page_unlock(zhdr); 1; }) : 1))); > > + } else { > > + zhdr = (struct z3fold_header *)(handle & PAGE_MASK); > > + } > > + > > + return zhdr; > > +} > > > > ... > > > > static unsigned short handle_to_chunks(unsigned long handle) > > { > > - unsigned long addr = *(unsigned long *)handle; > > + unsigned long addr; > > + struct z3fold_buddy_slots *slots = handle_to_slots(handle); > > + unsigned int seq; > > + > > + do { > > + seq = read_seqbegin(&slots->seqlock); > > + addr = *(unsigned long *)handle; > > + } while (read_seqretry(&slots->seqlock, seq)); > > It isn't done here (I think). handle_to_chunks() is always called with z3fold header locked which makes it a lot easier in this case. I'll add some comments in V2. Thanks, Vitaly