anolis: virtio-balloon: Add VIRTIO_BALLOON_F_ALLOC_RETRY

ANBZ: #8389

When VIRTIO_BALLOON_F_ALLOC_RETRY is set, virtio-balloon will use
__GFP_RETRY_MAYFAIL to allocate the pages but not __GFP_NORETRY.

Signed-off-by: Hui Zhu <teawater@antfin.com>
Reviewed-by: Issac Hai <hjwissac@linux.alibaba.com>
Acked-by: Liu Jiang <gerry@linux.alibaba.com>
Acked-by: Xunlei Pang <xlpang@linux.alibaba.com>
Signed-off-by: hr567 <hr567@linux.alibaba.com>
Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/2883
This commit is contained in:
Hui Zhu 2021-04-05 21:03:46 +08:00 committed by 小龙
parent fd410a0ae4
commit 7f66a6a984
4 changed files with 13 additions and 5 deletions

View File

@ -245,6 +245,12 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
struct page *page;
LIST_HEAD(pages);
bool is_cont = vb->current_pages_order != 0;
gfp_t gfp;
if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_ALLOC_RETRY))
gfp = __GFP_RETRY_MAYFAIL;
else
gfp = __GFP_NORETRY;
if (is_cont)
pfn_per_alloc = 2;
@ -262,7 +268,7 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
num - num_allocated_pages <
VIRTIO_BALLOON_PAGES_PER_PAGE << vb->current_pages_order)
continue;
page = balloon_pages_alloc(vb->current_pages_order);
page = balloon_pages_alloc(vb->current_pages_order, gfp);
if (page) {
/* If the first allocated page is not continuous pages,
* go back to transport page as signle page.
@ -1277,6 +1283,7 @@ static unsigned int features[] = {
VIRTIO_BALLOON_F_PAGE_POISON,
VIRTIO_BALLOON_F_REPORTING,
VIRTIO_BALLOON_F_CONT_PAGES,
VIRTIO_BALLOON_F_ALLOC_RETRY,
};
static struct virtio_driver virtio_balloon_driver = {

View File

@ -60,7 +60,7 @@ struct balloon_dev_info {
struct inode *inode;
};
extern struct page *balloon_pages_alloc(unsigned int order);
extern struct page *balloon_pages_alloc(unsigned int order, gfp_t gfp_mask);
extern void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
struct page *page);
extern void balloon_pages_enqueue(struct balloon_dev_info *b_dev_info,
@ -76,7 +76,7 @@ extern size_t balloon_page_list_dequeue_cont(struct balloon_dev_info *b_dev_info
static inline struct page *balloon_page_alloc(void)
{
return balloon_pages_alloc(0);
return balloon_pages_alloc(0, __GFP_NORETRY);
}
static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)

View File

@ -38,6 +38,7 @@
#define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */
#define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */
#define VIRTIO_BALLOON_F_CONT_PAGES 6 /* VQ to report continuous pages */
#define VIRTIO_BALLOON_F_ALLOC_RETRY 7 /* alloc pages with __GFP_RETRY_MAYFAIL */
/* Size of a PFN in the balloon interface. */
#define VIRTIO_BALLOON_PFN_SHIFT 12

View File

@ -121,10 +121,10 @@ EXPORT_SYMBOL_GPL(balloon_page_list_dequeue);
*
* Return: struct page for the allocated page or NULL on allocation failure.
*/
struct page *balloon_pages_alloc(unsigned int order)
struct page *balloon_pages_alloc(unsigned int order, gfp_t gfp_mask)
{
struct page *page = alloc_pages(balloon_mapping_gfp_mask() |
__GFP_NOMEMALLOC | __GFP_NORETRY |
__GFP_NOMEMALLOC | gfp_mask |
__GFP_NOWARN,
order);
return page;