From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754739AbdLLNU5 (ORCPT ); Tue, 12 Dec 2017 08:20:57 -0500 Received: from www262.sakura.ne.jp ([202.181.97.72]:39773 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752595AbdLLNUu (ORCPT ); Tue, 12 Dec 2017 08:20:50 -0500 To: wei.w.wang@intel.com, virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mst@redhat.com, mhocko@kernel.org, akpm@linux-foundation.org, mawilcox@microsoft.com Cc: david@redhat.com, cornelia.huck@de.ibm.com, mgorman@techsingularity.net, aarcange@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, willy@infradead.org, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu@aliyun.com, nilal@redhat.com, riel@redhat.com Subject: Re: [PATCH v19 3/7] xbitmap: add more operations From: Tetsuo Handa References: <1513079759-14169-1-git-send-email-wei.w.wang@intel.com> <1513079759-14169-4-git-send-email-wei.w.wang@intel.com> In-Reply-To: <1513079759-14169-4-git-send-email-wei.w.wang@intel.com> Message-Id: <201712122220.IFH05261.LtJOFFSFHVMQOO@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Tue, 12 Dec 2017 22:20:48 +0900 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wei Wang wrote: > +void xb_clear_bit_range(struct xb *xb, unsigned long start, unsigned long end) > +{ > + struct radix_tree_root *root = &xb->xbrt; > + struct radix_tree_node *node; > + void **slot; > + struct ida_bitmap *bitmap; > + unsigned int nbits; > + > + for (; start < end; start = (start | (IDA_BITMAP_BITS - 1)) + 1) { > + unsigned long index = start / IDA_BITMAP_BITS; > + unsigned long bit = start % IDA_BITMAP_BITS; > + > + bitmap = __radix_tree_lookup(root, index, &node, &slot); > + if (radix_tree_exception(bitmap)) { > + unsigned long ebit = bit + 2; > + unsigned long tmp = (unsigned long)bitmap; > + > + nbits = min(end - start + 1, BITS_PER_LONG - ebit); > + > + if (ebit >= BITS_PER_LONG) What happens if we hit this "continue;" when "index == ULONG_MAX / IDA_BITMAP_BITS" ? Can you eliminate exception path and fold all xbitmap patches into one, and post only one xbitmap patch without virtio-baloon changes? If exception path is valuable, you can add exception path after minimum version is merged. This series is too difficult for me to close corner cases. > + continue; > + bitmap_clear(&tmp, ebit, nbits); > + if (tmp == RADIX_TREE_EXCEPTIONAL_ENTRY) > + __radix_tree_delete(root, node, slot); > + else > + rcu_assign_pointer(*slot, (void *)tmp); > + } else if (bitmap) { > + nbits = min(end - start + 1, IDA_BITMAP_BITS - bit); > + > + if (nbits != IDA_BITMAP_BITS) > + bitmap_clear(bitmap->bitmap, bit, nbits); > + > + if (nbits == IDA_BITMAP_BITS || > + bitmap_empty(bitmap->bitmap, IDA_BITMAP_BITS)) { > + kfree(bitmap); > + __radix_tree_delete(root, node, slot); > + } > + } > + > + /* > + * Already reached the last usable ida bitmap, so just return, > + * otherwise overflow will happen. > + */ > + if (index == ULONG_MAX / IDA_BITMAP_BITS) > + break; > + } > +} > +/** > + * xb_find_next_set_bit - find the next set bit in a range > + * @xb: the xbitmap to search > + * @start: the start of the range, inclusive > + * @end: the end of the range, exclusive > + * > + * Returns: the index of the found bit, or @end + 1 if no such bit is found. > + */ > +unsigned long xb_find_next_set_bit(struct xb *xb, unsigned long start, > + unsigned long end) > +{ > + return xb_find_next_bit(xb, start, end, 1); > +} Won't "exclusive" loose ability to handle ULONG_MAX ? Since this is a library module, missing ability to handle ULONG_MAX sounds like an omission. Shouldn't we pass (or return) whether "found or not" flag (e.g. strtoul() in C library function)? bool xb_find_next_set_bit(struct xb *xb, unsigned long start, unsigned long end, unsigned long *result); unsigned long xb_find_next_set_bit(struct xb *xb, unsigned long start, unsigned long end, bool *found);